﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _gbook : System.Web.UI.Page
{
    public string Classn,straddtime;
	public string strcname,strtel,stremail,strcasetitle,strjudge,strcheckcode,strccontent,strcstatus;
    protected void Page_Load(object sender, EventArgs e)
    {

		Classn="在线留言";
		straddtime = DateTime.Now.ToString("yyyy-MM-dd");
		//新闻内容
		
		int gnum = (int)Socut.Data.ExecuteScalar("select count(*) from web_guestbook where Gdate ="+straddtime+"");
		if (gnum>30)
		{
			Response.Write("<script>alert('为了提高留言回复的质量，今天的留言条数限制已满，请明日再提交留言，谢谢您的关注！');history.back();</script>");
		}
		//Response.Write(gnum);
		//Response.End();
    
    }
	
	protected void Button2_Click(object sender, EventArgs e)
    {
        string Msg, Url;
		if (IsValid==true)
        {
            string Gname=this.Gname.Text.ToString();
            string Gaddress=this.Gaddress.Text.ToString();
            string Gemail=this.Gemail.Text.ToString();
            string Gtel=this.Gtel.Text.ToString();
            string Gtitle=this.Gtitle.Text.ToString();
			string Gcard=this.Gcard.Text.ToString();
			string iip=Request.UserHostAddress;
			int Gisshow = 0;
			//string Gisshow = this.Gisshow.SelectedValue.ToString();
            string Content=this.Content.Text.ToString();
			Content = htmlstr(Content);
			int Gcheck=0;
			//int Gis=Convert.ToInt32(Request.QueryString["gis"]);
			string Gdate=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");   

            
			Socut.Data.ExecuteNonQuery("insert into web_guestbook (Gname,Gaddress,Gemail,Gtel,Gtitle,Gisshow,Content,Gcheck,Gdate,Gip,Gcard) Values('"+Gname+"','"+Gaddress+"','"+Gemail+"','"+Gtel+"','"+Gtitle+"','"+Gisshow+"','"+Content+"','"+Gcheck+"','"+Gdate+"','"+iip+"','"+Gcard+"')");
			//Response.Write(LoginName.Text);
			//Response.End();
            Msg = "留言成功，谢谢您的参与！我们会按照您的要求给予回复，请耐心等待。";
            Url = "gbook.aspx";
			CommonFunction.ShowMessage(Msg,Url);
			
        }
    }


    public string htmlstr(string chr)
    {
        if (chr == null)
            return "";
        //chr = chr.Replace("<", "&lt");
        //chr = chr.Replace(">", "&gt");
        chr = chr.Replace("\n", "<br>");
        //chr = chr.Replace("\"", "&quot;");
        //chr = chr.Replace("'", "&#39;");
        //chr = chr.Replace(" ", "&nbsp;");
        chr = chr.Replace("select", "");
        chr = chr.Replace("delete", "");
        chr = chr.Replace("update", "");
        chr = chr.Replace("drop", "");
        //chr = chr.Replace(";", "");
        //chr = chr.Replace("(", "");
        //chr = chr.Replace(")", "");
        chr = chr.Replace("and", "");
        chr = chr.Replace("or", "");
        //chr = chr.Replace("\r", "");
        return (chr);
    }

    static bool IsNumeric(string str)
    {
        if (str == null || str.Length == 0)
            return false;
        foreach (char c in str)
        {
            if (!Char.IsNumber(c))
            {
                return false;
            }
        }
        return true;
    }
}
